#ifndef TC_MOMENTUM_HPP
#define TC_MOMENTUM_HPP

/** \file Momentum.hpp
 * Definition of the Momentum function template.
 *
 * (C) Copyright 2003-2006 by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Momentum.hpp 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */

#include "TA.hh"
#include "CircArray.hpp"


namespace TC {

  //! Momentum indicator. It is the ratio of the today's price
  //! compared to the price n period ago.
  TC_EXPORT template <typename InputIterator,
                      typename OutputIterator,
                      class Adaptor>
  void Momentum(InputIterator fromPos,
		InputIterator fromEnd,
		OutputIterator toPos,
		const unsigned period,
		const Adaptor adaptor)
  {
    // Types
    typedef typename Adaptor::Price_t Price_t;
    // Current price, 
    register Price_t pr;
    // Circular array of n-period prices
    CircArray<Price_t> pr_array(period+1);
    // Momentum value
    register TAfp_t mv;

    for(; fromPos!=fromEnd; ++fromPos) {
      pr = adaptor(*fromPos);
      pr_array.push(pr);
      // Calculate the momentum value
      mv = (pr / pr_array.at(0))*100;
      // Store the momentum value
      *toPos++ = mv;
    }

  }


} // end namespace


#endif /* Include guard */
